{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ec0720fc-a21e-4b12-8cb1-1c71d0fa49ee",
   "metadata": {},
   "source": [
    "# Lesson 3\n",
    "Import llama helper function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2231536-f799-4cc4-a70b-9cf8bb3aeb79",
   "metadata": {
    "height": 30
   },
   "outputs": [],
   "source": [
    "from utils import llama"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84c51a7d-f4f6-4917-85e8-b62d4a6db72d",
   "metadata": {},
   "source": [
    "### LLMs are stateless\n",
    "LLMs don't remember your previous interactions with them by default."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29f01f0f-18d3-4103-a5c5-e16d073ea8e1",
   "metadata": {
    "height": 97
   },
   "outputs": [],
   "source": [
    "prompt = \"\"\"\n",
    "    What are fun activities I can do this weekend?\n",
    "\"\"\"\n",
    "response = llama(prompt)\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8bfc928c-62b1-4159-aee5-1d29ea8b1621",
   "metadata": {
    "height": 97
   },
   "outputs": [],
   "source": [
    "prompt_2 = \"\"\"\n",
    "Which of these would be good for my health?\n",
    "\"\"\"\n",
    "response_2 = llama(prompt_2)\n",
    "print(response_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b02be5f2-9289-4c4e-b886-95c0f71dc1c6",
   "metadata": {},
   "source": [
    "### Constructing multi-turn prompts\n",
    "You need to provide prior prompts and responses as part of the context of each new turn in the conversation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09b0135e-3b53-42f7-ad04-821abed0a571",
   "metadata": {
    "height": 80
   },
   "outputs": [],
   "source": [
    "prompt_1 = \"\"\"\n",
    "    What are fun activities I can do this weekend?\n",
    "\"\"\"\n",
    "response_1 = llama(prompt_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "174d6d46-a985-4dc1-bc78-a780ac79c820",
   "metadata": {
    "height": 63
   },
   "outputs": [],
   "source": [
    "prompt_2 = \"\"\"\n",
    "Which of these would be good for my health?\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c28bb016-f6ba-40c8-9005-6d7a01c9c9b9",
   "metadata": {
    "height": 131
   },
   "outputs": [],
   "source": [
    "chat_prompt = f\"\"\"\n",
    "<s>[INST] {prompt_1} [/INST]\n",
    "{response_1}\n",
    "</s>\n",
    "<s>[INST] {prompt_2} [/INST]\n",
    "\"\"\"\n",
    "print(chat_prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a84eeb7-d9a9-43b8-ae45-84319acacbbd",
   "metadata": {
    "height": 63
   },
   "outputs": [],
   "source": [
    "response_2 = llama(chat_prompt,\n",
    "                 add_inst=False,\n",
    "                 verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71c6d6b0-e349-4b19-8deb-3a264f5ac549",
   "metadata": {
    "height": 29
   },
   "outputs": [],
   "source": [
    "print(response_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97681aed-60be-4090-a149-ec55980da388",
   "metadata": {},
   "source": [
    "### Use llama chat helper function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a40a7d1b-cf4a-49b3-ae85-c6e38dec3f64",
   "metadata": {
    "height": 29
   },
   "outputs": [],
   "source": [
    "from utils import llama_chat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "215f7036-14d1-4f95-bcb3-1c8de3a77628",
   "metadata": {
    "height": 80
   },
   "outputs": [],
   "source": [
    "prompt_1 = \"\"\"\n",
    "    What are fun activities I can do this weekend?\n",
    "\"\"\"\n",
    "response_1 = llama(prompt_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "345f48db-2908-4298-a056-67514cc45b39",
   "metadata": {
    "height": 63
   },
   "outputs": [],
   "source": [
    "prompt_2 = \"\"\"\n",
    "Which of these would be good for my health?\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc353f4a-970a-470e-aa1f-cab44c393261",
   "metadata": {
    "height": 46
   },
   "outputs": [],
   "source": [
    "prompts = [prompt_1,prompt_2]\n",
    "responses = [response_1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef09d61b-f6a9-4177-9682-7582bdbc342b",
   "metadata": {
    "height": 46
   },
   "outputs": [],
   "source": [
    "# Pass prompts and responses to llama_chat function\n",
    "response_2 = llama_chat(prompts,responses,verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c7cd767-3517-4f5e-9f11-708ec42e1e83",
   "metadata": {
    "height": 29
   },
   "outputs": [],
   "source": [
    "print(response_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3be0623-1d41-41bb-8bb5-261960761652",
   "metadata": {},
   "source": [
    "### Try it Yourself!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60b99648-3ce1-45ce-a2b5-7dffeed1eea9",
   "metadata": {
    "height": 165
   },
   "outputs": [],
   "source": [
    "# replace prompt_3 with your own question!\n",
    "prompt_3 = \"Which of these activites would be fun with friends?\"\n",
    "prompts = [prompt_1, prompt_2, prompt_3]\n",
    "responses = [response_1, response_2]\n",
    "\n",
    "response_3 = llama_chat(prompts, responses, verbose=True)\n",
    "\n",
    "print(response_3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae7864f5-1a60-4072-a7c9-3e9ccf3ec99d",
   "metadata": {
    "height": 29
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
